package initialize

import (
	"github.com/samber/do/v2"

	"gitee.com/monkeyPP/happy-mall/pkg/db"
	"gitee.com/monkeyPP/happy-mall/pkg/redis"
	"gitee.com/monkeyPP/happy-mall/services/userservice/internal/application"
	"gitee.com/monkeyPP/happy-mall/services/userservice/internal/domain/service"
	httpServer "gitee.com/monkeyPP/happy-mall/services/userservice/internal/infrastructure/http"
	"gitee.com/monkeyPP/happy-mall/services/userservice/internal/infrastructure/persistence"
	"gitee.com/monkeyPP/happy-mall/services/userservice/internal/infrastructure/server"
	"gitee.com/monkeyPP/happy-mall/services/userservice/internal/interfaces/api/handler"
)

var injector = do.New()

// Inject 依赖注入
func Inject() {
	// 创建 HTTP 服务器
	do.Provide(injector, httpServer.NewHTTPServerManager)
	do.Provide(injector, server.NewServerManager)

	do.Provide(injector, db.Init)
	do.Provide(injector, redis.Init)

	// user
	{
		do.Provide(injector, persistence.NewUserRepository)
		do.Provide(injector, service.NewUserService)
		do.Provide(injector, application.NewUserApp)
		do.Provide(injector, handler.NewUserHandler)
	}

	// auth
	{
		do.Provide(injector, handler.NewAuthHandler)
		do.Provide(injector, application.NewAuthApp)
	}
}

func GetInjector() *do.RootScope {
	return injector
}
